FROM nvcr.io/nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04

#添加作者信息
MAINTAINER xiaobo xiaobo@yunshicloud.com
#增加外挂磁盘，做为永久存储
ENV LANG=C.UTF-8
ENV LC_ALL=C.UTF-8
ENV TZ=Asia/Shanghai
#安装mariadb数据库
RUN apt -y update
# 更改容器的时区为 UTC+8
RUN export DEBIAN_FRONTEND=noninteractive
#RUN apt-get install -y tzdata
#RUN ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#RUN dpkg-reconfigure -f noninteractive tzdata
RUN apt -y install wget git
RUN apt -y install openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev libgd-dev gcc make curl nasm
RUN apt-get -y install build-essential libc6 libc6-dev unzip libnuma1 libnuma-dev
RUN apt-get -y install -y automake build-essential libass-dev libfreetype6-dev libsdl2-dev libtheora-dev libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev pkg-config texinfo zlib1g-dev
RUN apt -y install  yasm cmake 
RUN apt -y install  autoconf libtool
RUN apt -y install  g++
# 编译ffmpeg的环境
# 安装x264编码器
RUN mkdir -p /root/ffmpeg_source
WORKDIR /root/ffmpeg_source
RUN git clone https://gitee.com/mirrors/x264.git
WORKDIR /root/ffmpeg_source/x264
RUN PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static
RUN make
RUN make install
# 安装mp3编码器
WORKDIR /root/ffmpeg_source
RUN curl -O -L http://downloads.sourceforge.net/project/lame/lame/3.100/lame-3.100.tar.gz
RUN tar xzvf lame-3.100.tar.gz
WORKDIR /root/ffmpeg_source/lame-3.100
RUN ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --disable-shared --enable-nasm
RUN make
RUN make install
# 安装AAC编码器
WORKDIR /root/ffmpeg_source
RUN git clone https://gitee.com/xhh936/fdk-aac.git
WORKDIR /root/ffmpeg_source/fdk-aac
RUN autoreconf -fiv
RUN ./configure --prefix="$HOME/ffmpeg_build" --disable-shared
RUN make
RUN make install

WORKDIR /root/ffmpeg_source
COPY ./nv-codec-headers-n11.1.5.2.tar.gz /root/ffmpeg_source
# RUN wget https://github.com/FFmpeg/nv-codec-headers/archive/refs/tags/n11.1.5.2.tar.gz
RUN tar xvf nv-codec-headers-n11.1.5.2.tar.gz
WORKDIR /root/ffmpeg_source/nv-codec-headers-n11.1.5.2
RUN make
RUN make install

# 编译ffmpeg
WORKDIR /root/ffmpeg_source
RUN wget https://ffmpeg.org/releases/ffmpeg-4.2.9.tar.gz
RUN apt -y install libavformat-dev
RUN apt -y install libavcodec-dev
RUN apt -y install libswresample-dev
RUN apt -y install libswscale-dev
RUN apt -y install libavutil-dev
RUN apt -y install libsdl1.2-dev

RUN tar xvf ffmpeg-4.2.9.tar.gz
WORKDIR /root/ffmpeg_source/ffmpeg-4.2.9
ENV PATH="$HOME/bin:$PATH"
ENV PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" 
RUN ./configure \
  --prefix="$HOME/ffmpeg_build" \
  --pkg-config-flags="--static" \
  --bindir="$HOME/bin" \
  --enable-gpl \
  --enable-libfdk_aac \
  --enable-libfreetype \
  --enable-libmp3lame \
  --enable-libvorbis \
  --enable-libx264 \
  --enable-nonfree \
  --enable-libass \
  --enable-filter=subtitles \
  --enable-cuda \
  --enable-cuvid \
  --enable-nvenc \
  --extra-cflags="-I$HOME/ffmpeg_build/include -I/usr/local/cuda/include" \
  --extra-ldflags="-L$HOME/ffmpeg_build/lib -L/usr/local/cuda/lib64" \
  --extra-libs=-lpthread \
  --extra-libs=-lm
RUN make
RUN make install
RUN hash -r
RUN cp ffmpeg /usr/bin
RUN cp ffprobe /usr/bin
RUN ln -s /bin/python3 /bin/python
RUN apt -y install python3-pip
RUN apt -y install python3.10-venv
